package com.jinbo.footmessageworker.turn;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.baoyz.widget.PullRefreshLayout;
import com.jinbo.footmessageworker.BaseActivity;
import com.jinbo.footmessageworker.MyApplication;
import com.jinbo.footmessageworker.R;
import com.jinbo.footmessageworker.httpbean.OrdersBean;
import com.jinbo.footmessageworker.httpbean.TurnBean;
import com.jinbo.footmessageworker.httpbean.TurnsBean;
import com.jinbo.footmessageworker.httpretrofit.BusinessController;
import com.jinbo.footmessageworker.httpretrofit.Listener;
import com.jinbo.footmessageworker.utils.LocalPreferencesHelper;
import com.jinbo.footmessageworker.utils.TimeUtils;
import com.jinbo.footmessageworker.view.TitleBarView;

public class MoreTurnActivity extends BaseActivity implements View.OnClickListener {

    TextView day1Tv, day2Tv, day3Tv, day4Tv, day5Tv, day6Tv, day7Tv, day8Tv,
            day9Tv, day10Tv, day11Tv, day12Tv, day13Tv, day14Tv, day15Tv;//;
    View day1A, day2A, day3A, day4A, day5A, day6A, day7A, day8A, day9A, day10A,
            day11A, day12A, day13A, day14A, day15A;
    View day1B, day2B, day3B, day4B, day5B, day6B, day7B, day8B, day9B,
            day10B, day11B, day12B, day13B, day14B, day15B;
    View day1C, day2C, day3C, day4C, day5C, day6C, day7C, day8C,
            day9C, day10C, day11C, day12C, day13C, day14C, day15C;

    public static void launch(Activity activity) {
        Intent intent = new Intent(activity, MoreTurnActivity.class);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more_turn);
        TitleBarView titleBarView = (TitleBarView) findViewById(R.id.titleBar);
        titleBarView.setCenterTitle("班次");
        titleBarView.setLeftBackButtonIsVisibler(true);
        titleBarView.setListener(TitleBarView.TitleBarEnum.ll_leftBackImageLayout, this);
        initView();
        initData();
    }

    void initView() {

        day1Tv = (TextView) findViewById(R.id.day1);
        day2Tv = (TextView) findViewById(R.id.day2);
        day3Tv = (TextView) findViewById(R.id.day3);
        day4Tv = (TextView) findViewById(R.id.day4);
        day5Tv = (TextView) findViewById(R.id.day5);
        day6Tv = (TextView) findViewById(R.id.day6);
        day7Tv = (TextView) findViewById(R.id.day7);
        day8Tv = (TextView) findViewById(R.id.day8);
        day9Tv = (TextView) findViewById(R.id.day9);
        day10Tv = (TextView) findViewById(R.id.day10);
        day11Tv = (TextView) findViewById(R.id.day11);
        day12Tv = (TextView) findViewById(R.id.day12);
        day13Tv = (TextView) findViewById(R.id.day13);
        day14Tv = (TextView) findViewById(R.id.day14);
        day15Tv = (TextView) findViewById(R.id.day15);



        day1A=findViewById(R.id.day1_A);
        day2A=findViewById(R.id.day2_A);
        day3A=findViewById(R.id.day3_A);
        day4A=findViewById(R.id.day4_A);
        day5A=findViewById(R.id.day5_A);
        day6A=findViewById(R.id.day6_A);
        day7A=findViewById(R.id.day7_A);
        day8A=findViewById(R.id.day8_A);
        day9A=findViewById(R.id.day9_A);
        day10A=findViewById(R.id.day10_A);
        day11A=findViewById(R.id.day11_A);
        day12A=findViewById(R.id.day12_A);
        day13A=findViewById(R.id.day13_A);
        day14A=findViewById(R.id.day14_A);
        day15A=findViewById(R.id.day15_A);



        day1B=findViewById(R.id.day1_B);
        day2B=findViewById(R.id.day2_B);
        day3B=findViewById(R.id.day3_B);
        day4B=findViewById(R.id.day4_B);
        day5B=findViewById(R.id.day5_B);
        day6B=findViewById(R.id.day6_B);
        day7B=findViewById(R.id.day7_B);
        day8B=findViewById(R.id.day8_B);
        day9B=findViewById(R.id.day9_B);
        day10B=findViewById(R.id.day10_B);
        day11B=findViewById(R.id.day11_B);
        day12B=findViewById(R.id.day12_B);
        day13B=findViewById(R.id.day13_B);
        day14B=findViewById(R.id.day14_B);
        day15B=findViewById(R.id.day15_B);

        day1C=findViewById(R.id.day1_C);
        day2C=findViewById(R.id.day2_C);
        day3C=findViewById(R.id.day3_C);
        day4C=findViewById(R.id.day4_C);
        day5C=findViewById(R.id.day5_C);
        day6C=findViewById(R.id.day6_C);
        day7C=findViewById(R.id.day7_C);
        day8C=findViewById(R.id.day8_C);
        day9C=findViewById(R.id.day9_C);
        day10C=findViewById(R.id.day10_C);
        day11C=findViewById(R.id.day11_C);
        day12C=findViewById(R.id.day12_C);
        day13C=findViewById(R.id.day14_C);
        day15C=findViewById(R.id.day15_C);





    }

    void initData() {
        String user_id= MyApplication.local.getString(LocalPreferencesHelper.USER_ID);
        int  start_date= TimeUtils.getDay(TimeUtils.getNowMillis() - 24 * 60 * 60 * 1000);
        BusinessController.getInstance().turn(user_id, start_date, 20, new Listener<TurnsBean>() {
            @Override
            public void onStart(Object... params) {
                showProgressDialog("请稍后...");
                //mLoadView.setVisibility(View.VISIBLE);
                //mPullRefreshLayout.setRefreshing(true);
                //mLoadView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onComplete(TurnsBean result, Object... params) {
                dismissProgressDialog();
                //adapter.setorders(result.orders);
                // mPullRefreshLayout.setRefreshing(false);
                //mLoadView.setVisibility(View.GONE);
                // mCallBacks2.change(result.orders);
                // OrderActivity.this.
                // orders = result.orders;
                // mCallBacks2.change(result.orders);
                for(int i=0;i<result.turns.size();i++)
                {
                    if(i==0)
                      f(i,result.turns.get(i),day1Tv,day1A,day1B,day1C);
                    if(i==1)
                        f(i,result.turns.get(i),day2Tv,day2A,day2B,day2C);
                    if(i==2)
                        f(i,result.turns.get(i),day3Tv,day3A,day3B,day3C);
                    if(i==3)
                        f(i,result.turns.get(i),day4Tv,day4A,day4B,day4C);
                    if(i==4)
                        f(i,result.turns.get(i),day5Tv,day5A,day5B,day5C);
                    if(i==5)
                        f(i,result.turns.get(i),day6Tv,day6A,day6B,day6C);
                    if(i==6)
                        f(i,result.turns.get(i),day7Tv,day7A,day7B,day7C);
                    if(i==7)
                        f(i,result.turns.get(i),day8Tv,day8A,day8B,day8C);
                    if(i==8)
                        f(i,result.turns.get(i),day9Tv,day9A,day9B,day9C);
                    if(i==9)
                        f(i,result.turns.get(i),day10Tv,day10A,day10B,day10C);
                    if(i==10)
                        f(i,result.turns.get(i),day11Tv,day11A,day11B,day11C);
                    if(i==11)
                        f(i,result.turns.get(i),day12Tv,day12A,day12B,day12C);
                    if(i==12)
                        f(i,result.turns.get(i),day13Tv,day13A,day13B,day13C);
                    if(i==13)
                        f(i,result.turns.get(i),day14Tv,day14A,day14B,day14C);
                    if(i==14)
                        f(i,result.turns.get(i),day15Tv,day15A,day15B,day15C);


                }


            }

            @Override
            public void onFail(final String msg, Object... params) {
                // mLoadView.setVisibility(View.VISIBLE);
                dismissProgressDialog();
                //mLoadView.setVisibility(View.GONE);
                // mPullRefreshLayout.setRefreshing(false);
                if (TextUtils.isEmpty(msg)) {
                } else {
                    show(msg);
                }
            }
        });

    }
    void f(int i,TurnBean bean,TextView tv,View aV,View bV,View cV){
        if(i>2)
            tv.setText(TimeUtils.getMonth(TimeUtils.stringToMillis(bean.date)));
        if(bean.turn.equals("A")) {
            aV.setVisibility(View.VISIBLE);
        }
        else if(bean.turn.equals("B")) {
            bV.setVisibility(View.VISIBLE);
        }
        else if(bean.turn.equals("C")) {
            cV.setVisibility(View.VISIBLE);
        }

    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.left_back_layout:
                finish();
                break;
        }
    }
}
